var express = require('express');
var router = express.Router();
var statisticsdao = require('../dao/statisticsdao');

router.get('/task', function (req, res, next) {
    var isadmin = req.query.isadmin || 0;
    res.render('statistics/task', {
        isadmin: isadmin
    });
});

router.get('/task_statistics', function (req, res, next) {
    var taskid = req.query.taskid;
    var isadmin = req.query.isadmin == '' ? 0 : 1; //是否为任务管理员
    var key = req.query.key ||''; //查询条件
    var condition = {
        key: key,
        userid: req.session.user.userid,
        taskid: taskid,
        isadmin: isadmin
    };
    statisticsdao.getdataByTaskid(condition).then(function (data) {
        res.json({
            "code": 0,
            "msg": "",
            data: data[0][0]
        });
    }, function (error) {
        res.json({
            "code": 1,
            "msg": 'Data Error,Task is not start'
        });
    })
});
module.exports = router;